package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ScanCodeView
* */
class HistoryView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.SQUARE
            strokeJoin = Paint.Join.MITER
            color = context.resources.getColor(R.color.color_22F80A)
            style = Paint.Style.STROKE
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth / 2.0F
            val cy = mHeight / 2.0F
            val space = context.resources.getDimension(R.dimen.dp_2)
            mPaint0.strokeWidth = space
            val length0 = cx * 7 / 12
            val length1 = cx / 3
            translate(cx, cy)
            drawCircle(
                0F,
                0F,
                cx - space,
                mPaint0
            )
            mPath.apply {
                moveTo(0F, -length0)
                lineTo(0F, 0F)
                lineTo(length1, 0F)
            }
            drawPath(mPath, mPaint0)
        }
    }
}